package com.koron.css2.baseConfig.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;


/**
 * 创建用户编号
 * @author moningxi
 * @date 2023/10/11
 */
public class CreateUserNo implements ServerInterface {

    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        MessageBean<String> bean = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", String.class);
        try {
            GenerateNumber generateNumber = new GenerateNumberImpl();
            String userNo = generateNumber.generate(factory, "USER_INFO", userInfo.getCurWaterCode());
            bean.setData(userNo);
        } catch (Exception e) {
            bean.setCode(Constant.MESSAGE_DBFAIL);
            bean.setDescription("创建用户编号失败");
            logger.error("创建用户编号失败", e);
            factory.close(false);
        }
        return bean;
    }
}
